fn main() {

    //1.创建空String,不加mut没意义
    let mut s0 = String::new();
    s0.push_str("hello world");
    println!("s0 = {}",s0);

    //2.通过字面值创建String

    //2.1通过String::from创建
    let s1 = String::from("hello world");
    println!("s1 = {}",s1);

    //2.2 通过str创建
    let s2 = "hello world".to_string();
    println!("s2 = {}",s2);


    //3.更新String

    //push_str
    let mut s3 = String::from("hello world");
    let s4 = " !".to_string();
    s3.push_str(&s4);
    println!("s3 = {}",s3);

    //push
    let mut s5 = String::from("hello worl");
    s5.push('d');
    println!("s5 = {}",s5);

    //+
    let s6 = "hello ".to_string();
    let s7 = String::from("world");
    let s8 = s6 + &s7;
    println!("s8 = {}",s8);

    //format
    let s9 = String::from("hello");
    let s10 = String::from("world");
    let s11 = format!("{},{}",s9,s10);
    println!("s11 = {}",s11);

    //rust用utf-8编码,使用索引会出问题
    let s12 = String::from("hello world");
    //println!("s12[0] = {}",s12[0]);//error


    //遍历
    for char in s12.chars() {
        println!("{}",char)
    }

    

    println!("Hello, world!");
}
